
var $System = {
    DealUrl: function (vueApp, url, type, param) {
        switch (url) {
            ////删除
            case '/api/User/DeleteMuti': Mock.mock(host + url, type, function (options) {
                var delIDs = options.body;
                var temp = [];
                for (var i = 0; i < $System.Arrays.length; i++) {
                    temp.push($System.Arrays[i]);
                }
                for (var i = 0; i < temp.length; i++) {
                    if (delIDs.includes(temp[i].id)) {
$System.Arrays.splice(temp[i], 1);
                    }
                }
                return { result: "Success", message: null, data: null };
            }); break;
            //获取List数据
            case '/api/User/GetList': Mock.mock(host + url, type,
                function (options) {
                    if ($System.Arrays.length==0) {
                        $System.InitArray();
                    }
                    var p = JSON.parse(options.body);
                    //查询条件 写自己的查询条件 
                    var loginName = p.model.loginName;
                    var sex =  p.model.sex;
                    //分页条件
                    var offset = p.offset;
                    var limit = p.limit;
                    //查询条件 按自己实际的去过滤
                    var limitArrays2 = [];
                    for (var i = 0; i < $System.Arrays.length; i++) {
                        var user = $System.Arrays[i];
                        if (loginName && user.loginName.indexOf(loginName) == -1)
                            continue;
                        if (sex && user.sex.indexOf(sex) == -1)
                            continue;
                        limitArrays2.push(user);
                    }
                    var limitArrays = [];
                    for (var i = 0; i < limitArrays2.length; i++) {
                        if (i < offset + limit && i >= offset) {
                            limitArrays.push(limitArrays2[i]);
                        }
                    }
                    return {
                        result: "Success", message: null,
                        data: { pageData: limitArrays, rowCount: limitArrays2.length }
                    };
                }); break;
            //获取Input数据
            case '/api/User/get': Mock.mock(host + url + '?' + param, type, function (options) {
                var myArrays = parent.$System.Arrays;
                myarray = {};
                for (var i = 0; i < myArrays.length; i++) {
                    if (myArrays[i].id == vueApp.id) {
                        myarray = myArrays[i];
                        break;
                    }
                }
                return {
                    result: "Success", message: null, data: myarray
                };
            }); break;
            //提交
            case '/api/User/Save': Mock.mock(host + url, type, function (options) {
                var thisentity = JSON.parse(options.body);
                var thisArrays = parent.$System.Arrays;
                var cz = true;
                for (var i = 0; i < thisArrays.length; i++) {
                    //按自己实际的去修改内容
                    if (thisArrays[i].id == thisentity.id) {
                        thisArrays[i].loginName = thisentity.loginName;
                        thisArrays[i].name = thisentity.id;
                        thisArrays[i].password = thisentity.password;
                        thisArrays[i].sex = thisentity.sex;
                        thisArrays[i].remarks = thisentity.remarks;
                        thisArrays[i].lastUpdate = thisentity.lastUpdate;

                        cz = false;
                        break;
                    }
                }
                if (cz) {
                    //Input 页面需要 去操作List页面的数组 parent
                    //按自己实际的去添加内容
                    parent.$System.Arrays.unshift({
                        id: thisentity.id,
                        loginName: thisentity.loginName,
                        name: thisentity.name,
                        password: thisentity.password,
                        sex: thisentity.sex,
                        remarks: thisentity.remarks,
                        lastUpdate: thisentity.lastUpdate

                    });
                }

                return { result: "Success", message: null, data: null };
            }); break;


        }


    },
    Arrays: [],
    InitArray: function(){
        for (var i = 0; i < 20; i++) {
            //注意  随机数据初始都是随机姓名，需要自己手动调整
            $System.Arrays.push(Mock.mock({
                loginName: Mock.Random.cname(),
                password: Mock.Random.cname(),
                name: Mock.Random.cname(),
                lastUpdate: Mock.Random.date(),
                remarks: Mock.mock('@county(true)'),
                sex: randomKey('01'),
                id: Mock.Random.id()
            }));

        }
    }
}




